pub struct Solution;

impl Solution {
    pub fn convert_to_base7(num: i32) -> String {
        if num == 0 { return String::from('0'); }
        let flag = num < 0;
        let mut result = String::new();
        let mut tmp = num.abs();
        while tmp != 0 {
            let i = tmp % 7;
            result.insert_str(0, &i.to_string());
            tmp /= 7;
        }
        if flag {
            result.insert_str(0, "-");
        }
        result
    }

    pub fn add_strings(num1: String, num2: String) -> String {
        let bigger = if num1.len() > num2.len() { num1.clone() } else { num2.clone() };
        let smaller = if num1.len() > num2.len() { num2 } else { num1 };
        let mut tmp = "0".repeat(bigger.len() - smaller.len());
        tmp.push_str(&smaller);
        let mut flag = 0;
        let mut result = String::new();
        bigger.chars().rev().zip(tmp.chars().rev())
            .for_each(|(ch1, ch2)| {
                let sum = ch1.to_digit(10).unwrap() + ch2.to_digit(10).unwrap() + flag;
                result.insert_str(0, (sum % 10).to_string().as_str());
                flag = if sum >= 10 { 1 } else { 0 };
            });
        if flag == 1 { result.insert_str(0, "1") }
        result
    }
}